package com.fengjue.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fengjue.common.RespBean;
import com.fengjue.common.RespPageBean;
import com.fengjue.pojo.Employee;
import com.fengjue.pojo.Salary;
import com.fengjue.service.IEmployeeService;
import com.fengjue.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工账套
 */
@RestController
@RequestMapping("/salary/sobcfg")
public class SalarySobCfgController {

    @Autowired
    private ISalaryService salaryService;

    @Autowired
    private IEmployeeService employeeService;

    @ApiOperation("获取所有工资账套")
    @GetMapping("/salaries")
    public List<Salary> getAllSalaries() {
        return salaryService.list();
    }

    @ApiOperation("获取所有员工账套")
    @GetMapping
    public RespPageBean getEmployeeWithSalary(
            @RequestParam(defaultValue = "1") Integer currentPage,
            @RequestParam(defaultValue = "10") Integer size
    ) {
        return employeeService.getEmployeeWithSalary(currentPage, size);
    }

    @ApiOperation(value = "更新工资账套")
    @PutMapping
    public RespBean updateEmployeeSalary(Integer eid,Integer sid){
        if (employeeService.update(
                new UpdateWrapper<Employee>().set("salaryId",sid).eq("id",eid)
        )){
            return RespBean.success("更新工资账套成功");
        }
        return RespBean.error("更新工资账套失败");
    }
}
